home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
asm_n_z.zip
/
WILD.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-03-16
|
38KB
|
853 lines
; WILD Public Domain 1988 by Charles Lazo III, v1.0
; WILD.ASM This program is used to run any other program (or DOS command)
; by expanding program wild card parameters given on the command
; line. E.g., WILD PROG *.* would run a program, say PROG.EXE,
; multiple times and supply it each time with a file from the
; current directory matching *.* (i.e., every file in the current
; directory would be supplied to PROG for execution).
rt equ 0dh
lf equ 0ah
of equ offset
bptr equ byte ptr
wp equ word ptr
code segment
assume cs:code, ds:code
org 2ch
env_seg dw ? ; pointer to segment of our environment
org 100h
begin: jmp start
;-------------------------------------------------------------------------------
; The wild card specification is placed here at the bottom of our stack to avoid
; having to specially set aside space for it. It is used by the find_first
; routine to find the first file in the current directory meeting the wild card
; specification using the DOS Find First function.
;-------------------------------------------------------------------------------
wild_spec db 16 dup('STACK ') ; 128 bytes for stack
our_stack label word
ss_save dw ? ; place to store ss:sp
sp_save dw ?
memory_used dw ? ; keep track of memory paragraphs used
env_size dw ? ; number of bytes in the environment stored here
cspc_addr label dword
dw 2 dup(?); store address of comspec variable here
left_blank dw ? ; stores pointer to start of wild card spec
right_blank dw ? ; stores pointer to end of wild card spec
copy_size dw ? ; stores size of command on command line (WILD)
buffer_ptr dw 0 ; pointer to buffer for list of filenames
switches db 0 ; record presence of QUERY & NOEXT here
file_attr dw 0 ; store file attributes for file find
cmd_line db 128 dup(0) ; save original command line here
cmdl db ?,'/c',128 dup(?) ; command line for EXEC
;-------------------------------------------------------------------------------
; The parameter table to be passed to the DOS EXEC function:
;-------------------------------------------------------------------------------
params dw ? ; segment of environment block stored here
dw of cmdl ; offset of command line for program EXECed
dw ? ; segment of command line for program EXECed
dw 55h ; offset of first FCB
dw ? ; segment of first FCB
dw 65h ; offset of second FCB
dw ? ; segment of second FCB
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
; The following routines (up to the label buffer:) operate under the assumption
; that both ds and es are set to the code segment of WILD.
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;-------------------------------------------------------------------------------
; When the WILD environment variable has NOEXT in its assignment string, then
; filename extensions are ignored (not supplied) when commands are passed to
; the DOS EXEC function. This routine will remove any extension from the file-
; name in the DTA placed there by the DOS Find First and Continue File Search
; functions if NOEXT was found in the WILD environment variable. The extension
; is removed by replacing the period separating the main part from the extension
; with a null. Note that if a period is the only part of the filename, then it
; must be the dot representing the current directory so it is not removed.
;-------------------------------------------------------------------------------
remove_ext? proc near ; removes any extension from filename
test switches,noe ; is WILD NOEXT env variable set?
jz no_remove ; no, don't remove extension
xor al,al ; find null terminating filename
mov cx,14 ; max number of characters in ASCIIZ+1
cld ; (for maintenance and documentation)
repne scasb ; search for null
sub di,9eh ; compute number of filename characters
mov cx,di ; and place it in cx for next search
mov al,'.' ; search for period prior to extension
mov di,9eh ; offset of filename in DTA
repne scasb ; search for period
jcxz no_remove ; can't remove extension if not there
cmp di,9fh ; if the period was the ONLY character,
jz no_remove ; then it is the current directory
mov bptr [di-1],0 ; set it to null to remove the extension
no_remove: ret
remove_ext? endp
;-------------------------------------------------------------------------------
; find_size computes the length of a filename in the DTA placed there by the DOS
; find first and continue file search functions. The length of the filename is
; returned in cx (the null character at the end of the ASCIIZ string is included
; in the count). This routine is similar to file_size, qv.
;-------------------------------------------------------------------------------
find_size proc near ; find size of filename (returned in cx)
call remove_ext? ; eliminate filename extension?
xor al,al ; find null at end of ASCIIZ filename
mov di,9eh ; offset of filename in DTA
mov cx,14 ; max number of characters in ASCIIZ+1
cld ; (for maintenance and documentation)
repne scasb ; search for null in ASCIIZ filename
sub di,9eh ; compute number of filename characters
mov cx,di ; return value in cx
ret
find_size endp
;-------------------------------------------------------------------------------
; In this routine we check to see if there is enough memory presently allocated
; for the filename buffer to place another filename in the buffer. First di is
; is set to the location in the buffer where the next filename will go. If not
; enough memory has been allocated to allow the placement of another filename
; in the buffer, then more memory is allocated. By using only the memory that
; is needed by the buffer (additional memory is allocated in blocks of 16 para-
; graphs or 256 bytes; an arbitrary value) the remaining memory can be used in
; the EXEC call.
;-------------------------------------------------------------------------------
set_di proc near ; sets di to point to next available
mov di,buffer_ptr ; location in filename buffer
push cx ; save filename size
or di,di ; is it zero (uninitialized)?
jz init_di ; yes, point it to start of buffer
mov bx,di ; use bx to find paragraphs used now
add bx,0fh ; round up to next paragraph
shr bx,1 ; determine paragraph count
shr bx,1
shr bx,1
shr bx,1
inc bx ; reserve one more than used
mov ax,memory_used ; memory paragraphs presently allocated
cmp bx,ax ; is memory to be used > allocated?
ja get_more ; yes, get more memory
di_set: pop cx ; restore filename size
ret
get_more: add ax,16 ; ask for 256 more bytes (16 paragraphs)
mov bx,ax ; request sent in bx
mov dx,ax ; store in dx to assure request granted
mov ah,4ah ; DOS memory modify function (es is ok)
int 21h ; ask DOS for it
cmp bx,dx ; DOS give what we wanted?
mov dx,of mem_need ; address error message in case not
jz got_it ; got requested memory
jmp error_exit ; nope, DOS don't have it, terminate
init_di: mov di,of buffer
jmp short di_set ; exit with di at start of buffer
got_it: mov memory_used,bx ; update memory allocated
pop cx ; restore filename size
ret
set_di endp
;-------------------------------------------------------------------------------
; With this call we copy the filename in the DTA (placed there by DOS Find First
; and Continue File Search functions) into the filename buffer.
;-------------------------------------------------------------------------------
store_filename proc near ; store filename of file find in buffer
call find_size ; find size of filename in DTA (to cx)
call set_di ; set di to next location in buffer
mov si,9eh ; offset of filename in DTA
cld ; (for maintenance and documentation)
rep movsb ; move ASCIIZ filename to buffer
mov buffer_ptr,di ; update buffer pointer
ret
store_filename endp
;-------------------------------------------------------------------------------
; This one is similar t